#ifndef Q_LEAF_NODE_H
#define Q_LEAF_NODE_H

#include "QNode.h"
#include "Bucket.h"
#include "contest_interface.h"

class QInternalNode;

const int MAX_LEAF_SIZE = 4;

class QLeafNode : public QNode {
private:
    static const int type = 2;

public:
    Bucket bucket;
    QLeafNode* nextRightLeafNode;
    QLeafNode* nextLeftLeafNode;
    QInternalNode* parent;
    uint32_t childID;

public:
    QLeafNode(QNode* parentNode, uint32_t childID, QNode* nextRightNode,
            QNode* nextLeftNode);
    QLeafNode(QNode* parent, uint32_t childID);
    void destruct(bool flag);
    ~QLeafNode(void);

    ErrorCode insertBucketRecord(Record *r);
    ErrorCode deleteBucketRecord(Record *r, bool flagMatchDuplicates);
    ErrorCode deleteBucketRecord(Key *k, bool flagMatchDuplicates);
    ErrorCode updateBucketRecord(Record *record, Block *new_payload,
            bool flagMatchDuplicates);
    ErrorCode updateBucketRecord(Key *k, Block *new_payload,
            bool flagMatchDuplicates);

    /*For Update and Delete without commit- just to return the list of records that need to be affected*/
    ErrorCode fakeModifyRecord(Record *r, Iterator **it, bool flagMatchDuplicates);
    ErrorCode fakeModifyRecord(Key *k, Iterator **it, bool flagMatchDuplicates);

    ErrorCode find(Key *k, Iterator ** iterator);
    ErrorCode findRange(Key *min, Key *max, Iterator** records);
    ErrorCode findPartial(Key *k, Iterator** records);

    //override

    int getType() const {
        return type;
    }
};

#endif /* Q_LEAF_NODE_H */
